#ifndef AIPREDICTIONWIDGET_H
#define AIPREDICTIONWIDGET_H

#include <QWidget>
#include <QMap>
#include <QSqlQuery>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QDebug>
#include <QMessageBox>

#include <QJsonObject>
#include <QJsonArray>
#include <QJsonDocument>


namespace Ui {
class AIPredictionWidget;
}

class AIPredictionWidget : public QWidget
{
    Q_OBJECT

public:
    explicit AIPredictionWidget(QWidget *parent = nullptr);
    ~AIPredictionWidget();

    void setEnvironmentData(int tempTime, int humidityTime, int lightTime);
    void loadCropData();

    void http_recv(QNetworkReply* reply);

    void Ui_PushButton();

private slots:
    void on_cropComboBox_currentIndexChanged(int index);
    void on_getAdviceButton_clicked();

    void on_addCropButton_clicked(); // 添加自定义作物按钮
    void on_saveCustomCropButton_clicked(); // 保存自定义作物

private:
    Ui::AIPredictionWidget *ui;

    struct CropRequirement {
        QString name;
        float minTemp;
        float maxTemp;
        int minHumidity;
        int maxHumidity;
        int minLight;
        int maxLight;
        int idealTempTime;  // 小时
        int idealHumidityTime; // 小时
        int idealLightTime; // 小时
    };

    QMap<QString, CropRequirement> cropRequirements;

    int currentTempTime = 0;
    int currentHumidityTime = 0;
    int currentLightTime = 0;

    QNetworkAccessManager *manger;
};

#endif // AIPREDICTIONWIDGET_H
